﻿<%@ Page CodeFileBaseClass="AliCMS.Lib.SystemPageBase" %>
<script language="c#" runat="server">
protected string Condition()
{
	StringBuilder condition = new StringBuilder();
	string and = String.Empty;

	#region 是否回收
	string isRecycled = Request.QueryString["IsRecycled"];
	if (isRecycled == null)
		condition.Append(and + Alias.Mail.IsDeleted + "=false");
	else if (isRecycled != String.Empty)
		condition.Append(and + Alias.Mail.IsDeleted + "=" + isRecycled);
	#endregion

	if (and == String.Empty && condition.Length != 0)
		and = " AND ";

	#region 地区
	string regionID = Request.QueryString["RegionID"];
	if (!String.IsNullOrEmpty(regionID))
	{
		if (Convert.ToBoolean(Request.QueryString["IncludeSubRegion"]))
		{
			condition.Append(and + Alias.Mail.IncludeSubRegion + "=" + regionID);
		}
		else
		{
			if (regionID == "0")
				condition.Append(and + Alias.Mail.RegionID + " IS NULL");
			else
				condition.Append(and + Alias.Mail.RegionID + "=" + regionID);
		}
	}
	#endregion
	
	if (and == String.Empty && condition.Length != 0)
		and = " AND ";

	#region 行业
	string industryID = Request.QueryString["IndustryID"];
	if (!String.IsNullOrEmpty(industryID))
	{
		if (Convert.ToBoolean(Request.QueryString["IncludeSubIndustry"]))
		{
			condition.Append(and + Alias.Mail.IncludeSubIndustry + "=" + industryID);
		}
		else
		{
			if (industryID == "0")
				condition.Append(and + Alias.Mail.IndustryID + " IS NULL");
			else
				condition.Append(and + Alias.Mail.IndustryID + "=" + industryID);
		}
	}
	#endregion

	if (and == String.Empty && condition.Length != 0)
		and = " AND ";

	#region 关键词
	string keyword = Request.QueryString["Keyword"];
	if (!String.IsNullOrEmpty(keyword))
	{
		if (Request.QueryString["KeywordType"] == "Subject")
			condition.Append(and + Alias.Mail.Subject + " LIKE '%" + keyword + "%'");
	}
	#endregion
	
	return condition.ToString();
}

protected string Sort()
{
	string sort = String.Empty;
	switch (Request.QueryString["Sort"])
	{
		case "1":
			sort = Alias.Mail.UpdateTime + " DESC";
			break;
		case "2":
			sort = Alias.Mail.UpdateTime + " ASC";
			break;
	}
	
	return sort;
}
</script>
<table border="0" cellpadding="4" cellspacing="1" class="ListTable">
	<thead>
		<tr>
			<th width="40">选择</th>
			<th>主题</th>
			<th>行业</th>
			<th>地区</th>
			<th>标签</th>
			<th>对象</th>
			<th>发送方式</th>
			<th>最后运行</th>
			<th>运行次数</th>
			<th width="40">日志</th>
		</tr>
	</thead>
	<tbody>
		<ali:List ID="List" Object="Mail" Page="PageNumber" PageSize="20" Condition="Condition()" Sort="Sort()" Validate="True">
			<ali:Record>
				<tr ItemID="<%=InnerID%>">
					<td><input type="checkbox" name="Sel" value="<%=InnerID%>"  /></td>
					<td class="<%=ContentLang%>Font"><a href="../mail/edit.aspx?Lang=<%=ContentLang%>&ID=<%=InnerID%>"><%=Subject%></a></td>
					<td class="<%=ContentLang%>Font"><%=IndustryName%></td>
					<td class="<%=ContentLang%>Font"><%=RegionName%></td>
					<td class="<%=ContentLang%>Font"><%=TagName%></td>
					<td>
						<%If Convert.ToBoolean(ToCompany)%>
							企业
						<%Else%>
							个人
						<%EndIf%>
					</td>
					<td>
						<%If Convert.IsDBNull(Every)%>
							手动执行
						<%ElseIf String.Equals(Every, "Once")%>
							定时执行
						<%Else%>
							周期执行
						<%EndIf%>
					</td>
					<td><%=LastRun%></td>
					<td><%=RunTimes%></td>
					<td><a href="../mail/log/list.aspx?Lang=<%=ContentLang%>&ID=<%=InnerID%>">日志</a></td>
				</tr>
			</ali:Record>
		</ali:List>
	</tbody>
</table>
<ali:Pagination Page="PageNumber" PageSize="20" RecordCount="List[RecordCount]">
<div class="Pagination">
	<div class="Left">共 <%=RecordCount%> 条 当前显示第 <%=PageNumber%> 页 第 <%=RangeLower%>-<%=RangeUpper%> 条 </div>
	<div class="Right">
		<ali:FirstPage>
			<ali:Yes>
				<img src="<%=ImagePath%>pagination/first_page_off.gif"/>
				<img src="<%=ImagePath%>pagination/previous_page_off.gif"/>
			</ali:Yes>
			<ali:No>
				<a href="javascript:Go(1)"><img src="<%=ImagePath%>pagination/first_page_on.gif"/></a>
				<a href="javascript:Go(<%=PageNumber%> - 1)" id="PrevPage"><img src="<%=ImagePath%>pagination/previous_page_on.gif"/></a>
			</ali:No>
		</ali:FirstPage>
		<ali:CurrentPage Range="5">
			<ali:Yes>
				<span class="Current"><%=Index%></span>						
			</ali:Yes>
			<ali:No>
				<a href="javascript:Go(<%=Index%>)">[<%=Index%>]</a>
			</ali:No>
		</ali:CurrentPage>
		<ali:LastPage>
			<ali:Yes>
				<img src="<%=ImagePath%>pagination/next_page_off.gif"/>
				<img src="<%=ImagePath%>pagination/last_page_off.gif"/>
			</ali:Yes>
			<ali:No>
				<a href="javascript:Go(<%=PageNumber%> + 1)" id="NextPage"><img src="<%=ImagePath%>pagination/next_page_on.gif"/></a>
				<a href="javascript:Go(<%=PageCount%>)"><img src="<%=ImagePath%>pagination/last_page_on.gif"/></a>
			</ali:No>
		</ali:LastPage>
	</div>
</div>
</ali:Pagination>